/* 
 * File:   image.h
 * Author: gustavo
 *
 * Created on January 6, 2012, 2:55 AM
 */

#ifndef IMAGE_H
#define	IMAGE_H

#ifdef	__cplusplus
extern "C" {
#endif

#include <util/mem.h>
#include "../matrix/matrix.h"


#include "../object/object.h"

#define IMP_IMAGE_TYPE			( imp_image_get_class() )
#define IMP_IS_IMAGE(obj)		( imp_object_is_from_class (obj, IMP_IMAGE_TYPE ) )
#define IMP_IMAGE(obj)			IMP_OBJECT_CAST (obj, ImpImage, IMP_IMAGE_TYPE )
#define IMP_IMAGE_CLASS(klass)	IMP_OBJECT_CLASS_CAST (klass, ImpImageClass, IMP_IMAGE_TYPE )


#define imp_image_idx( img, x, y) ( ( (int)(x) + ( (int)( (y)*(img)->width) ) ) * (img)->nchannels )

	typedef enum _imp_image_type ImpImageType;
	typedef struct _imp_image ImpImage;
	typedef struct _imp_image_class ImpImageClass;

	enum _imp_image_type {
		IMP_IMAGE_TYPE_GRAY,
		IMP_IMAGE_TYPE_RGB
	};

	struct _imp_image {
		extends(ImpObject);

		int height;
		int width;
		int nchannels;
		int npixels;
		int nbytes;
		unsigned char * data;

		int stride;
		ImpImageType type;
	};

	struct _imp_image_class {
		extends(ImpObjectClass);

	};

	ImpObjectClass * imp_image_get_class(void);
	boolean imp_image_set_data(ImpImage * Img, void * data, int height, int width, ImpImageType type);
	boolean imp_image_constructor(ImpImage * Img, int width, int height, ImpImageType type);
	ImpImage * imp_image_new(int width, int height, ImpImageType type);

	// =========================================================================

#define imp_image_delete( Img ) { mem_free(Img->data); mem_free(Img); }
	int imp_image_get_stride(int width, ImpImageType type); 
	void imp_image_clear(ImpImage * Img);
	/* ====================================================================== */
	void imp_image_mat2gray(ImpMatrix * Mat, ImpImage ** Gray);
	void imp_image_mat2rgb(ImpMatrix * Mat, ImpImage ** RGB);
	void imp_image_gray2mat(ImpImage * Gray, ImpMatrix ** Mat);
	void imp_image_rgb2gray(ImpImage * RGB, ImpImage ** Gray);
	void imp_image_gray2rgb(ImpImage * Gray, ImpImage ** RGB);


#ifdef	__cplusplus
}
#endif

#endif	/* IMAGE_H */

